<!DOCTYPE html>
<html lang="en">
    <head>
        <meta charset="UTF-8" />
        <meta http-equiv="X-UA-Compatible" content="IE=edge" />
        <meta name="viewport" content="width=device-width, initial-scale=1.0" />
        <title>Document</title>
    </head>
    <body>
        <script>
            /* 
            思路：传入23,那么首先从abc里面选一个，然后从def里选。所以需要还是需要传每次递归的下标起始点，
            这样才能从map中找到对应的字符串进行循环
            */
            var letterCombinations = function (digits) {
                if (!digits.length) return []
                const map = { 2: 'abc', 3: 'def', 4: 'ghi', 5: 'jkl', 6: 'mno', 7: 'pqrs', 8: 'tuv', 9: 'wxyz' }
                const res = []
                function backTracking(path, start) {
                    if (path.length == digits.length) {
                        return res.push([...path].join(''))
                    }
                    //下标0 对应的digits[0]==2  然后map里就可以找到对应的字符串了
                    let arr = map[digits[start]]
                    for (let i = 0; i < arr.length; i++) {
                        path.push(arr[i])
                        backTracking(path, start + 1)
                        path.pop()
                    }
                }
                backTracking([], 0)
                return res
            }
        </script>
    </body>
</html>
